package com.goresor.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.google.api.client.googleapis.GoogleUrl;

/**
 * Fabrique des urls google pour interroger les API google.
 *
 */
@Component
public class GoogleUrlFactory {

	private static final String LATITUDE_URI = "https://www.googleapis.com/latitude/v1";
	
	@Value("${goresor.api.key}")
	private String goResorApiKey;
	
	private Boolean prettyPrint=Boolean.TRUE;
	
	public GoogleUrl getLatitudeUrlForCurrentLocation(){
		GoogleUrl url = buildLatitudeUrl();
		url.pathParts.add("currentLocation");
		return url;
	}
	
	public GoogleUrl getLatitudeUrlForLocation(Long timestamp) {
		GoogleUrl url = buildLatitudeUrl();
		url.pathParts.add("location");
		url.pathParts.add(timestamp.toString());
		return url;
	}
	
	public GoogleUrl getLatitudeUrlForLocations(){
		GoogleUrl url = buildLatitudeUrl();
		url.pathParts.add("location");
		return url;
	}
	
	private GoogleUrl buildLatitudeUrl(){
		GoogleUrl url = new GoogleUrl(LATITUDE_URI);
		url.set("prettyprint", prettyPrint);
		url.set("key",goResorApiKey);
		return url;
	}
}
